<?php
require_once 'Artdepot/ImageHelper.php';
class Model_Artwork extends Zend_Db_Table_Row
{
	public function getPhotoPhysicalPath($size=null) {
		$origFile = PUBLIC_PATH . '/images/artwork_images/original/' . $this->photo;
		if (empty($size)) {
			return $origFile;
		}
		$resizedFile = PUBLIC_PATH . '/images/artwork_images/resized/' . $size . '_' . $this->photo;
		if (!file_exists($resizedFile) && is_readable($origFile)) {
			ImageHelper::resize($origFile, $resizedFile, $size);
		}
		return $resizedFile;
	}
	
	public function getPhotoWebAccessablePath($size=null) {
		if (empty($size)) {
			return '/images/artwork_images/original/' . $this->photo;
		}
		$this->getPhotoPhysicalPath($size);
		return '/images/artwork_images/resized/' . $size . '_' . $this->photo;
	}
	
	public function getArtistObj(){
		$table = new Model_DbTable_Artist();
		return $table->fetchRow("id = $this->artist");
	}
	
	public function getSubjectsObj(){
		$table = new Model_DbTable_Subject();
		if ($this->subject) {
			return $table->fetchAll("id IN ($this->subject)");
		}else {
			return null;
		}
		
	}
	
	public function getCategoryObj(){
		$table = new Model_DbTable_ArtworkCategory();
		return $table->fetchRow("id = $this->category");
	}
	
	public function getStylesObj(){
		$table = new Model_DbTable_Styles();
		return $table->fetchAll("id IN ($this->style)");
	}
}

